import { defineStore } from "pinia";
import axios from 'axios';
import { nanoid } from 'nanoid'
import { reactive } from 'vue'


export const useContentStore = 
defineStore('content',()=>{
  // 数据 谨记要包裹到一个动态数据里 使用 ref 或 reactive
  let list = reactive(JSON.parse(localStorage.getItem('list') as string) || [])
  // 方法
  async function add(){
    let { data: { content: title } } = await axios.get('https://api.uomg.com/api/rand.qinghua?format=json')
    list.unshift({ id: nanoid(), title });
  }
  // 返回
  return {list,add}
})